﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace DoNet.Common.Utilities
{
    public class SerializationHelper
    {
		public static byte[] SerializeBinary (object request)
		{
			MemoryStream serializationStream = new MemoryStream();
			new BinaryFormatter().Serialize(serializationStream, request);
			byte[] buffer = new byte[serializationStream.Length];
			serializationStream.Position = 0;
			serializationStream.Read(buffer, 0, buffer.Length);
			return buffer;
		}
		
		public static object DeserializeBinary (byte[] buf)
		{
			MemoryStream serializationStream = new MemoryStream(buf);
			serializationStream.Position = 0;
			object obj1 = new BinaryFormatter().Deserialize(serializationStream);
			serializationStream.Close();
			return obj1;
		}
		
        //public static string SerializeSOAP (object request)
        //{
        //    MemoryStream stream1 = new MemoryStream();
        //    new SoapFormatter().Serialize(stream1, request);
        //    byte[] buffer = new byte[stream1.Length];
        //    stream1.Position = 0;
        //    stream1.Read(buffer, 0, buffer.Length);
        //    return Encoding.Default.GetString(buffer);
        //}
		
        //public static object DeserializeSOAP (string xml)
        //{
        //    MemoryStream stream1 = new MemoryStream(Encoding.Default.GetBytes(xml));
        //    stream1.Position = 0;
        //    object obj1 = new SoapFormatter().Deserialize(stream1);
        //    stream1.Close();
        //    return obj1;
        //}
    }
}
